#include<iostream>
using namespace std;
int n;
int arr[1010];
int s[1010];
int main()
{
	
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> arr[i];
		s[i] = arr[i] + s[i - 1];
	}
	int mi = s[0];
	int ans = -1e9;
	for (int i = 1; i <= n; i++) {
		ans = max(ans, s[i] - mi);
		mi = min(mi, s[i]);
	}
	cout << ans << endl;
	return 0;
}